package com.example.springboot.mapper;

import com.example.springboot.pojo.User;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface UserMapper {

    //根据房间号查业主
    @Select("select * from user where room_number=#{roomNumber}")
    User findByRoomNumber(String roomNumber);

    //查询业主列表
    @Select("select * from user")
    List<User> getAllUser();

    //新增业主
    @Insert("insert into user(room_number,name,id,phone_number,password,email)" +
            " values(#{roomNumber},#{name},#{id},#{phoneNumber},#{password},#{email})")
    void addUser(String roomNumber, String name, String id, String phoneNumber, String password, String email);

    @Update("update user set name=#{name},id=#{id},phone_number=#{phoneNumber},email=#{email} where room_number=#{roomNumber}")
    void updateUser(String roomNumber, String name, String id, String phoneNumber, String email);

    @Delete("delete from user where room_number=#{roomNumber}")
    void deleteUser(String roomNumber);

    @Update("update user set password=#{password} where email=#{email}")
    void updatePassword(String email,String password);

    @Select("select * from user where email=#{email}")
    User findByEmail(String email);
}

